package servlets.users;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ActivateUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String URL = "http://localhost:8080/DatabaseRESTWebService/ActivateUser?userId=";

	protected void doPut(HttpServletRequest request,
			HttpServletResponse response) {
		String userId = "", inputLine;
		BufferedReader reader;
		StringBuffer responseBuffer;

		userId = request.getParameter("userId");

		try {
			String url = URL + userId;
			String cleanUrl = url.replace(" ", "%20");

			HttpURLConnection httpConnection = (HttpURLConnection) new URL(
					cleanUrl).openConnection();
			httpConnection.setRequestMethod("PUT");
			httpConnection.setDoOutput(true);
			httpConnection.setDoInput(true);
			httpConnection.setRequestProperty("Content-Type",
					"application/x-www-form-urlencoded");

			reader = new BufferedReader(new InputStreamReader(
					httpConnection.getInputStream()));

			responseBuffer = new StringBuffer();

			while ((inputLine = reader.readLine()) != null) {
				responseBuffer.append(inputLine);
			}
			reader.close();
			
			try {
				response.getWriter().write("Success");
			}
			catch(Exception e) {
				
			}
		} catch (Exception e1) {

		}
	}
}
